import logging
import os
# import yaml

def get_logger(cfg):
    if not os.path.exists(cfg['output_dir']):
        os.mkdir(cfg['output_dir'])
    # cfg.OUTPUT_DIR = os.path.join(cfg.OUTPUT_DIR, cfg.DATASET.NAME)
    # if not os.path.exists(cfg.OUTPUT_DIR):
    #     os.mkdir(cfg.OUTPUT_DIR)
    
    # with open(os.path.join(cfg['output_dir'], '%s.yaml'%cfg['dataset']['name']), "w") as f:
    #     yaml.dump(cfg, f)


    log_file = '%s/%s.log' % (cfg['output_dir'], cfg['model']['name'])
    if os.path.exists(log_file):
        os.remove(log_file)
        
    logging.basicConfig(
        format=
        '[%(asctime)s] [%(levelname)s] %(message)s',
        level=logging.INFO,
        handlers=[
            logging.FileHandler(log_file, mode='w'),
            logging.StreamHandler()
        ])
    return logging
